
<#

.SYNOPSIS 
Hydration Script Module - MSISupport

.DESCRIPTION
Hydration Environment for MDTEx Powershell Common Modules
Common MSI Support.

.NOTES
Copyright Keith Garner (KeithGa@DeploymentLive.com), All rights reserved.

.LINK
http://MDTEx.CodePlex.com

#>


function Get-MSIProperties ( $Path )
{
	if(!(Test-Path $Path))
	{
		throw "Could not find $Path"
	}
    $FullPath = (get-item $Path).FullName

	write-host "Open: $FullPath"
	$WindowsInstaller = New-Object -com WindowsInstaller.Installer
	$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase","InvokeMethod",$Null,$WindowsInstaller,@($FullPath,0))
	if ( $MSIDatabase )
	{
		$View = $MSIDatabase.GetType().InvokeMember("OpenView","InvokeMethod",$null,$MSIDatabase,"SELECT * FROM Property") 
		$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null) | out-null
		while($Record = $View.GetType().InvokeMember("Fetch","InvokeMethod",$null,$View,$null)) 
		{
			@{ $Record.GetType().InvokeMember("StringData","GetProperty",$null,$Record,1) = 
	 		   $Record.GetType().InvokeMember("StringData","GetProperty",$null,$Record,2)}
		}
		$View.GetType().InvokeMember("Close","InvokeMethod",$null,$View,$null) | out-null
	}

}

function Get-UninstallKey ( $Key )
{
	if ( test-path "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Key" )
	{
		return "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Key"
	}
	elseif ( test-path "HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$Key" )
	{
		return "HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$Key"
	}
}


